package com.dmz.workflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dmz.workflow.base.BaseServiceImpl;
import com.dmz.workflow.dao.WorkflowDictionaryMapper;
import com.dmz.workflow.service.WorkflowDictionaryService;
import com.dmz.workflow.entity.Dictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkflowDictionaryServiceImpl extends BaseServiceImpl<WorkflowDictionaryMapper, Dictionary> implements WorkflowDictionaryService {

    @Autowired
    private WorkflowDictionaryMapper workflowDictionaryMapper;

    @Override
    public List<Dictionary> selectDictionaryByProcessInstanceId(String processInstanceId) {
        LambdaQueryWrapper<Dictionary> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Dictionary::getProcessInstanceId, processInstanceId);
        return workflowDictionaryMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public void updateBackDictionary(String processInstanceId, String srcNodeId, String tarNodeId) {
        LambdaUpdateWrapper<Dictionary> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(Dictionary::getProcessInstanceId, processInstanceId)
                .eq(Dictionary::getCode, srcNodeId);
        Dictionary dictionary = new Dictionary();
        dictionary.setCode(tarNodeId);
        workflowDictionaryMapper.update(dictionary, lambdaUpdateWrapper);
    }
}
